﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.Utility;

namespace EnvironmentManagerSystem.Finance
{
    public partial class Statistics : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                BindGv();
            }
        }

        private void BindGv()
        {
            gvList.DataSource = XIANGMU.GetAlreadyReceive(hidStart.Value, hidEnd.Value);
            gvList.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            hidStart.Value = txtStart.Text.Trim();
            hidEnd.Value = txtEnd.Text.Trim();
            BindGv();
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            hidStart.Value = string.Empty;
            hidEnd.Value = string.Empty;
            txtStart.Text = string.Empty;
            txtEnd.Text = string.Empty;
            //foreach (Control con in this.form1.Controls)
            //{
            //    if (con is TextBox)
            //        ((TextBox)con).Text = string.Empty;
            //    if (con is HiddenField)
            //        ((HiddenField)con).Value = string.Empty;
            //}
        }

        protected void gvList_DataBound(object sender, EventArgs e)
        {
            double SumStandardMoney = 0;
            double SumActualMoney = 0;
            foreach (GridViewRow row in gvList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    try
                    {
                        if (row.Cells[8].Text != string.Empty && row.Cells[8].Text != null)
                            SumActualMoney += double.Parse(row.Cells[8].Text);
                        if (row.Cells[7].Text.Trim() != string.Empty && row.Cells[7].Text != null)
                            SumStandardMoney += double.Parse(row.Cells[7].Text);
                    }
                    catch { }
                }
            }
            labStandard.Text = "标准合同金额："+SumStandardMoney.ToString()+"万元";
            labActual.Text = "应收合同金额：" + SumActualMoney.ToString() + "万元";
        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            OfficeHelper.HelpDv(e.Row);
        }

        protected void gvList_PageIndexChanged(object sender, EventArgs e)
        {
            BindGv();
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvList.PageIndex = e.NewPageIndex;
        }
    }
}
